package com.tzy.for10evalue.haoyong.excelexport.consumerservice;

import com.aebiz.baseframework4ms.exception.AppException;
import com.aebiz.plugins.b2b.common.dto.product.productunit.plugins.productunit_p2.params.ProductUnitExcelDTO;
import com.aebiz.plugins.b2b.product.business.unitmgr.productunit.plugins.productunit_p2.service.ProductUnit_P2Service;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yuzw
 * @Description: 品牌批量导入（新）
 * @date 2022/10/20 14:01
 */
@Service("unitBatchImportNewService")
public class UnitBatchImportNewServiceImpl extends AbstractProductBatchImportNewHandler<ProductUnitExcelDTO> {

    @Autowired
    private ProductUnit_P2Service productUnit_P2Service;
    @Override
    protected ProductUnitExcelDTO parseObject(String message) {
        return JSON.parseObject(message, ProductUnitExcelDTO.class);
    }

    @Override
    protected void checkImportExcel(ProductUnitExcelDTO excelDTO) {
        //校验
        if(StringUtils.isBlank(excelDTO.getUnitName())) {
            throw new AppException("第" + excelDTO.getLineId() + "行单位名称不能为空");
        }
        if(excelDTO.getUnitName().length() > 50) {
            throw new AppException("第" + excelDTO.getLineId() + "行单位【"+excelDTO.getUnitName()+"】名称长度不能大于50个字符");
        }
    }

    @Override
    protected String execute(ProductUnitExcelDTO excelDto) {
        checkImportExcel(excelDto);
        productUnit_P2Service.createProductBrandForBase(excelDto, excelDto.getApiParamDTO());//实际导入
        return excelDto.getUnitName();
    }

    @Override
    protected String getKeyWord(ProductUnitExcelDTO excelDto) {
        return excelDto.getUnitName();
    }

    @Override
    protected Integer getLineId(ProductUnitExcelDTO excelDto) {
        return excelDto.getLineId();
    }

    @Override
    protected String getExcelName(ProductUnitExcelDTO excelDto) {
        return excelDto.getExcelName();
    }

    @Override
    public Integer getType() {
        return 5;
    }
}
